<template>
  <div :style="{height:height}">
      <el-button v-if="isTab" @click="btncancel">返回</el-button>
      <div :style="'text-align:right;' + 'height:' + (isTab ? 'calc(100% - 23px);' : '100%;')">
          <vxe-table :data.sync="tableDataRptLog" ref="xTableRptLog" height="100%" :loading="RptLogloading" @cell-click="LogSingleClick" @cell-dblclick="LogDblClick" :sort-config="{ trigger: 'cell' }" show-overflow border size="mini" show-header-overflow highlight-current-row highlight-hover-row resizable stripe>
              <vxe-table-column field="log_date" title="操作日期" width="150" sortable header-align="center"></vxe-table-column>
              <vxe-table-column field="rptlogtypename" title="操作类型" width="90" sortable align="center"></vxe-table-column>
              <vxe-table-column field="log_username" title="操作者" width="100" sortable align="center"></vxe-table-column>
              <vxe-table-column field="log_content" title="操作内容" width="200" sortable header-align="center"></vxe-table-column>
              <vxe-table-column field="computer_name" title="操作时机器名" width="100" sortable header-align="center">
                  <template v-slot="{ row }">
                      <span style="color:blue;">{{row.computer_name}}</span>
                      <i class="el-icon-refresh" @click="repalceComputerName(row)"></i>
                  </template>
              </vxe-table-column>
              <!-- <vxe-table-column field="reportflag" title="报告标志" width="120" sortable header-align="center" ></vxe-table-column> -->
              <vxe-table-column field="mac_address" title="操作时机器MAC" width="120" sortable header-align="center"></vxe-table-column>
              <!-- <vxe-table-column field="rptunitid" title="报告单元ID" width="120" sortable header-align="center" ></vxe-table-column>
              <vxe-table-column field="sampledate" title="标本日期" width="120" sortable header-align="center" ></vxe-table-column>
              <vxe-table-column field="sampleno" title="标本号" width="80" sortable header-align="center"></vxe-table-column> -->
              <vxe-table-column field="reportid" title="报告ID" width="160" sortable header-align="center"></vxe-table-column>
          </vxe-table>
      </div>
      <el-dialog :append-to-body="true" :close-on-click-modal="false" :visible.sync="dialogDetailVisible" title="检验报告修改详细内容" top="5vh" width="800px">
          <vxe-table :data.sync="tableDataRptLogDetail" ref="xTableRptLog" height="400px" :loading="RptLogDetailloading" :sort-config="{ trigger: 'cell' }" show-overflow border size="mini" show-header-overflow highlight-current-row highlight-hover-row resizable stripe>
              <vxe-table-column field="rpt_logid" title="日志明细ID" width="100" sortable header-align="center"></vxe-table-column>
              <vxe-table-column field="objecttype" title="修改类型" width="100" sortable header-align="center"></vxe-table-column>
              <vxe-table-column field="columnname" title="修改对象" width="160" sortable header-align="center"></vxe-table-column>
              <vxe-table-column field="oldvalue" title="修改/复查前取值" width="160" sortable header-align="center"></vxe-table-column>
              <vxe-table-column field="newvalue" title="修改/复查后取值" width="160" sortable header-align="center"></vxe-table-column>
          </vxe-table>
      </el-dialog>
  </div>
</template>
<script>
export default {
  props: { reportid: { type: String }, isShowBtn: { type: Boolean, default: true }, height: { type: String, default: "400px" }, showreqlog: { type: Number, default: 0 } },
  data() {
      return {
          myreportid: this.reportid,
          tableDataRptLog: [],
          RptLogloading: false,
          tableDataRptLogDetail: [],
          dialogDetailVisible: false,
          RptLogDetailloading: false,
          isTab: this.isShowBtn == false ? false : true
      };
  },
  updated() {},
  created() {
      if (this.myreportid) {
          this.QueryRptLog(this.myreportid);
      }
  },
  methods: {
      QueryRptLog(reportid) {
          this.tableDataRptLog = [];
          this.RptLogloading = true;
          this.$tool
              .request({
                  url: "/ucent/reportlog",
                  method: "post",
                  data: {
                      action: "getReportlog",
                      reportid: reportid,
                      showreqlog: this.showreqlog
                  }
              })
              .then(res => {
                  this.RptLogloading = false;
                  if (res.errcode == "1") {
                      this.tableDataRptLog = res.Data;
                      if (this.tableDataRptLog && this.tableDataRptLog.length > 0) {
                          this.LogSingleClick({ row: this.tableDataRptLog[0] });
                      }
                  }
                  else {
                      this.$alert(res.msg, "错误", {
                          confirmButtonText: "确定",
                      });
                  }
              });
      },
      QueryLogDetail(logid) {
          return new Promise((s, f) => {
              this.RptLogDetailloading = true;
              this.$tool
                  .request({
                      url: "/ucent/reportlog",
                      method: "post",
                      data: {
                          action: "getReportlogdetail",
                          rpt_logid: logid
                      }
                  })
                  .then(res => {
                      if (res.errcode == "1") {
                          this.tableDataRptLogDetail = res.Data;
                      }
                      this.RptLogDetailloading = false;
                      s(this.tableDataRptLogDetail);
                  })
                  .catch(() => {
                      f();
                  });
          });
      },
      LogDblClick({ row, rowIndex }) {
          this.QueryLogDetail(row.rpt_logid);
          this.dialogDetailVisible = true;
      },
      LogSingleClick({ row, rowIndex }) {
          this.QueryLogDetail(row.rpt_logid).then(d => {
              this.$emit("loaddetail", d);
          });
      },
      btncancel() {
          this.$emit("cancel");
      },
      repalceComputerName(row) {
          this.$pub.getComputerName(row.mac_address)
              .then((name)=> {
                  row.computer_name = name;
              })
              .catch(()=> {
                  this.$message.error("机器名称查询失败！");
                  //保持原样
              });
      },
  }
};
</script>
<style scoped>
.el-main {
  padding: 0;
}
</style>
